{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Episode 1: Intro to Conversational AI and Rasa"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Start the event loop\n",
    "\n",
    "Running asynchronous Rasa code in Jupyter Notebooks requires an extra requirement, since Jupyter Notebooks already run on event loops. Run the cell below to start the event loop:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import nest_asyncio\n",
    "\n",
    "nest_asyncio.apply()\n",
    "print(\"Event loop ready.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Create a new project and train an example assistant\n",
    "\n",
    "Create a new project called **rasabot**. The function below will create a new project with example training data and most important files. It replicates the behaviour of Rasa CLI function **rasa init**.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import rasa\n",
    "from rasa.cli.scaffold import create_initial_project\n",
    "import os\n",
    "\n",
    "project = \"rasabot\"\n",
    "create_initial_project(project)\n",
    "\n",
    "# move into project directory and show files\n",
    "os.chdir(project)\n",
    "print(os.listdir(\".\"))\n",
    "\n",
    "# define the project files\n",
    "config = \"config.yml\"\n",
    "training_files = \"data/\"\n",
    "domain = \"domain.yml\"\n",
    "output = \"models/\"\n",
    "\n",
    "#train the example assistant\n",
    "model_path = rasa.train(domain, config, [training_files], output)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Have a chat with an assistant\n",
    "\n",
    "The function above creates an assistant called moodbot which asks how you feel and if you are sad it tries to cheer your up with a picture of a cute tiger cub. You can test an assistant using the functions below. To stop the chat type '/stop' in a chat window.\n",
    "The code cell below replicates the behaviour of the Rasa CLI function **rasa shell**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from rasa.jupyter import chat\n",
    "chat(model_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
